﻿using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AnesSystem.Models;

namespace AnesSystem.Controls
{
    /// <summary>
    /// ParamerterCellCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class ParamerterCellCtrl : BaseVitalCellCtrl
    {

        #region Variables


        #endregion

        #region Constructor

        public ParamerterCellCtrl()
        {
            InitializeComponent();
            _txtValue.FontSize = RealTimeSignShowUtil.CELLFONTSIZE;
            _txtValue.Height = RealTimeSignShowUtil.CELLHEIGHT - 3;
            _txtValue.Width = RealTimeSignShowUtil.CELLWIDTH - 3;
            this._txtValue.Background = this.Background;
            LeftVital = new PatientVitalSignsModel();
            _txtValue.PreviewMouseLeftButtonDown += _txtValue_PreviewMouseLeftButtonDown;
            _txtValue.LostFocus += _txtValue_LostFocus;
            _txtValue.GotFocus += _txtValue_GotFocus;
            _txtValue.TextChanged += _txtValue_TextChanged;
            this.Loaded += ParamerterCellCtrl_Loaded;
        }

        #endregion

        #region Properties


        #endregion

        #region 依赖属性

        public override bool IsReadOnly
        {
            get { return _isReadOnly; }
            set
            {
                if (value)
                {
                    _txtValue.IsEnabled = false;
                }
                else
                {
                    _txtValue.IsEnabled = true;
                }
            }
        }

        #endregion

        #region Event


        #endregion

        #region Private Methods

        #endregion

        #region Public/Protected Methods

        public override void SetFocus()
        {
            this._txtValue.Focus();
            _txtValue.SelectAll();
        }

        #endregion

        #region EventHandlers

        private void _txtValue_TextChanged(object sender, TextChangedEventArgs e)
        {
            IngValue = (sender as TextBox).Text;
        }

        private void _txtValue_LostFocus(object sender, RoutedEventArgs e)
        {
            _txtValue.Foreground = (Brush)(new BrushConverter()).ConvertFromString("#666666");
            _txtValue.PreviewMouseLeftButtonDown += _txtValue_PreviewMouseLeftButtonDown;
        }

        private void _txtValue_GotFocus(object sender, RoutedEventArgs e)
        {
            if (IsReadOnly) return;
            RealTimeSignLeftCtrlViewModel.Instance.SelectedIndex = RowIndex - 1;
            _txtValue.Foreground = (Brush)(new BrushConverter()).ConvertFromString("#00b1cb");
            _txtValue.SelectAll();
            _txtValue.PreviewMouseLeftButtonDown -= _txtValue_PreviewMouseLeftButtonDown;
        }

        private void ParamerterCellCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            SelfVital = this.DataContext as PatientVitalSignsModel;
        }
        private void _txtValue_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            _txtValue.Focus();
            e.Handled = true;
        }

        #endregion


    }
}
